package com.panasonic.cn.cmsc;

import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
import java.sql.SQLException;
import com.fujitsu.fks.jaaf.core.*;

public class SQLMM9702{
	private Hashtable paramsString     = new Hashtable();
	private Hashtable paramsBigDecimal = new Hashtable();
	private Hashtable paramsFree       = new Hashtable();
	private String lastSql_ = null;

	private String getString(String name){
		if(name==null) return "";
		String returnStr = (String)paramsString.get(name);
		if(returnStr==null) return "";
		return "'"+FrameworkCommon.stringReplaceSQuote(returnStr)+"'";
	}

	private String getBigDecimal(String name){
		if(name==null) return "";
		BigDecimal returnStr = (BigDecimal)paramsBigDecimal.get(name);
		if(returnStr==null) return "";
		return returnStr.toString();
	}

	private String getFree(String name){
		if(name==null) return "";
		String returnStr = (String)paramsFree.get(name);
		if(returnStr==null) return "";
		return returnStr;
	}

	public String getLastSql(){
		return lastSql_;
	}

	public SelectResultRset SelectM01_1(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT ");
		sql.append("  NVL( M01.VDR_CD,'') AS VDR_CD,");
		sql.append("	NVL( M01.TRPT_NM_CN,'') AS TRPT_NM_CN,");
		sql.append("	NVL( M05.ITM_NO,'') AS ITM_NO,");
		sql.append("	NVL( M02.ITM_NM_CN,'') AS ITM_NM_CN,");
		sql.append("	NVL( M01.CUS_PRC_TAB_CD,'') AS CUS_PRC_TAB_CD,");
		sql.append("	NVL( M05.CUS_PRC_TAB_CN,'') AS CUS_PRC_TAB_CN,");
		sql.append("	NVL( M05.SLS_PRIZ,'') AS SLS_PRIZ,");
		sql.append("	NVL( M03.SLS_STD_S_PRIZ,'') AS SLS_STD_S_PRIZ");
		sql.append("	FROM ");
		sql.append("	M01,M03,M05,M02");
		sql.append("	WHERE ");
		sql.append("	M01.VDR_CD "+((getString("VDR_CD").equals(""))?" is null ":"=")+getString("VDR_CD")+"								");
		sql.append("	AND	M01.TRPT_CLSS_D_TYP "+((getString("SLCP_TRPT_CLSS_TYP_01").equals(""))?" is null ":"=")+getString("SLCP_TRPT_CLSS_TYP_01")+"								");
		sql.append("	AND	M01.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+" and "+getString("APL_BDT")+"<= M01.APL_EDT							");
		sql.append("	AND	M01.FM_TYP <> "+getString("FM_TYP_6")+" 								");
		sql.append("	AND	M01.FM_TYP <> "+getString("FM_TYP_9")+" 							");
		sql.append("	AND	M01.CTRL_DVSN_CD = M05.SLCP_CD								");
		sql.append("	AND	M01.CUS_PRC_TAB_CD = M05.CUS_CD	");
		sql.append("	AND	M05.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+"  and "+getString("APL_BDT")+"<= M05.APL_EDT								");
		sql.append("	AND	M05.FM_TYP <> "+getString("FM_TYP_6")+" 									");
		sql.append("	AND	M05.FM_TYP <> "+getString("FM_TYP_9")+" 								");
		sql.append("	AND	M05.ITM_NO = M03.ITM_NO								");
		sql.append("	AND	M05.SLCP_CD = M03.SLCP_CD								");
		sql.append("	AND	M03.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+" and "+getString("APL_BDT")+" <= M03.APL_EDT								");
		sql.append("	AND	M03.FM_TYP <> "+getString("FM_TYP_6")+" 								");
		sql.append("	AND	M03.FM_TYP <> "+getString("FM_TYP_9")+" 								");
		sql.append("	AND	M05.ITM_NO = M02.ITM_NO");
		sql.append("	ORDER BY VDR_CD,ITM_NO(+)");
		sql.append("	");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}

	public SelectResultRset SelectM01_2(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT ");
		sql.append("  NVL( M01.VDR_CD,'') AS VDR_CD,");
		sql.append("	NVL( M01.TRPT_NM_CN,'') AS TRPT_NM_CN,");
		sql.append("	NVL( M05.ITM_NO,'') AS ITM_NO,");
		sql.append("	NVL( M02.ITM_NM_CN,'') AS ITM_NM_CN,");
		sql.append("	NVL( M01.CUS_PRC_TAB_CD,'') AS CUS_PRC_TAB_CD,");
		sql.append("	NVL( M05.CUS_PRC_TAB_CN,'') AS CUS_PRC_TAB_CN,");
		sql.append("	NVL( M05.SLS_PRIZ,'') AS SLS_PRIZ,");
		sql.append("	NVL( M03.SLS_STD_S_PRIZ,'') AS SLS_STD_S_PRIZ");
		sql.append("	FROM ");
		sql.append("	M01,M03,M05,M02");
		sql.append("	WHERE ");
		sql.append("	M01.VDR_CD "+((getString("VDR_CD").equals(""))?" is null ":"=")+getString("VDR_CD")+"		          					");
		sql.append("	AND	M01.TRPT_CLSS_D_TYP "+((getString("SLCP_TRPT_CLSS_TYP_01").equals(""))?" is null ":"=")+getString("SLCP_TRPT_CLSS_TYP_01")+"								");
		sql.append("	AND	M01.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+" and "+getString("APL_BDT")+"<= M01.APL_EDT							");
		sql.append("	AND	M01.FM_TYP <> "+getString("FM_TYP_6")+" 								");
		sql.append("	AND	M01.FM_TYP <> "+getString("FM_TYP_9")+" 								");
		sql.append("	AND	M01.CTRL_DVSN_CD = M05.SLCP_CD								");
		sql.append("	AND	M01.CUS_PRC_TAB_CD = M05.CUS_CD								");
		sql.append("	AND	M05.ITM_NO LIKE "+getString("ITM_NO")+"								");
		sql.append("	AND	M05.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+"  and "+getString("APL_BDT")+"<= M05.APL_EDT								");
		sql.append("	AND	M05.FM_TYP <> "+getString("FM_TYP_6")+" 									");
		sql.append("	AND	M05.FM_TYP <> "+getString("FM_TYP_9")+" 								");
		sql.append("	AND	M05.ITM_NO = M03.ITM_NO								");
		sql.append("	AND	M05.SLCP_CD = M03.SLCP_CD								");
		sql.append("	AND	M03.APL_BDT <"+((getString("APL_BDT").equals(""))?" is null ":"=")+getString("APL_BDT")+" and "+getString("APL_BDT")+" <= M03.APL_EDT								");
		sql.append("	AND	M03.FM_TYP <> "+getString("FM_TYP_6")+" 							");
		sql.append("	AND	M03.FM_TYP <> "+getString("FM_TYP_9")+" 								");
		sql.append("	AND	M05.ITM_NO = M02.ITM_NO");
		sql.append("	ORDER BY VDR_CD,ITM_NO(+)");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}


	public void setVDR_CD(String value){
		if(value==null) {
			paramsString.remove("VDR_CD");
			return;
		}
		paramsString.put("VDR_CD",value);
	}


	public void setSLCP_TRPT_CLSS_TYP_01(String value){
		if(value==null) {
			paramsString.remove("SLCP_TRPT_CLSS_TYP_01");
			return;
		}
		paramsString.put("SLCP_TRPT_CLSS_TYP_01",value);
	}


	public void setAPL_BDT(String value){
		if(value==null) {
			paramsString.remove("APL_BDT");
			return;
		}
		paramsString.put("APL_BDT",value);
	}


	public void setFM_TYP_6(String value){
		if(value==null) {
			paramsString.remove("FM_TYP_6");
			return;
		}
		paramsString.put("FM_TYP_6",value);
	}


	public void setFM_TYP_9(String value){
		if(value==null) {
			paramsString.remove("FM_TYP_9");
			return;
		}
		paramsString.put("FM_TYP_9",value);
	}


	public void setITM_NO(String value){
		if(value==null) {
			paramsString.remove("ITM_NO");
			return;
		}
		paramsString.put("ITM_NO",value);
	}


}
